{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import jieba"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<generator object Tokenizer.cut at 0x00000211BB817BA0>\n"
     ]
    }
   ],
   "source": [
    "tempstr = \"郭靖与华山三十六剑\"\n",
    "res=jieba.cut(tempstr)# 返回一个generator的迭代对象\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Building prefix dict from the default dictionary ...\n",
      "Dumping model to file cache C:\\Users\\ADMINI~1.DES\\AppData\\Local\\Temp\\jieba.cache\n",
      "Loading model cost 0.969 seconds.\n",
      "Prefix dict has been built successfully.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "郭靖/与/华山/三十六/剑\n"
     ]
    }
   ],
   "source": [
    "print(\"/\".join(res))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "郭靖\n",
      "与\n",
      "华山\n",
      "三十六\n",
      "剑\n"
     ]
    }
   ],
   "source": [
    "# 直接输出列表\n",
    "lres = jieba.cut(tempstr)\n",
    "for item in lres:\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "郭/靖/与/华山/三十/三十六/十六/剑\n"
     ]
    }
   ],
   "source": [
    "# 全模式\n",
    "res_all = jieba.cut(tempstr,cut_all=True)\n",
    "print(\"/\".join(res_all))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "郭靖/与/华山/三十/十六/三十六/剑\n"
     ]
    }
   ],
   "source": [
    "# 搜索引擎模式\n",
    "res_search = jieba.cut_for_search(tempstr)\n",
    "print(\"/\".join(res_search))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
